\hypertarget{group__pustowka__encoder}{
\section{ENCODER Library}
\label{group__pustowka__encoder}\index{ENCODER Library@{ENCODER Library}}
}


Interrupt-\/driven encoder library for odometry readings.  
\subsection*{Defines}
\begin{DoxyCompactItemize}
\item 
\#define \hyperlink{group__pustowka__encoder_gad221dba2d598f81f78bb66ec479c9a93}{ENC\_\-FORWARD}~0
\begin{DoxyCompactList}\small\item\em Constant used to define the behavior of the encoders. \item\end{DoxyCompactList}\item 
\#define \hyperlink{group__pustowka__encoder_ga67c39a2a0310bf458988c9965f480562}{ENC\_\-REVERSE}~1
\begin{DoxyCompactList}\small\item\em Constant used to define the behavior of the encoders. \item\end{DoxyCompactList}\item 
\#define \hyperlink{group__pustowka__encoder_gad22ac75fffb7e44913bff8e3916972a8}{ENC\_\-LEFT}~0
\begin{DoxyCompactList}\small\item\em Constant used in \hyperlink{group__pustowka__encoder_gadaa18e9376adb2838d4db7b819070083}{encoders\_\-read()} function. \item\end{DoxyCompactList}\item 
\#define \hyperlink{group__pustowka__encoder_ga27432c06a7d08af0da6941f75127a0bd}{ENC\_\-RIGHT}~1
\begin{DoxyCompactList}\small\item\em Constant used in \hyperlink{group__pustowka__encoder_gadaa18e9376adb2838d4db7b819070083}{encoders\_\-read()} function. \item\end{DoxyCompactList}\item 
\#define \hyperlink{group__pustowka__encoder_ga050a620db67d2e9687e40295e0d29722}{encoders\_\-resetRight}()~encoders\_\-writeRight(0)
\begin{DoxyCompactList}\small\item\em Resets right encoder. \item\end{DoxyCompactList}\item 
\#define \hyperlink{group__pustowka__encoder_gafc6b8648337ac6e21a67245c288b12a8}{encoders\_\-resetLeft}()~encoders\_\-writeLeft(0)
\begin{DoxyCompactList}\small\item\em Resets left encoder. \item\end{DoxyCompactList}\item 
\#define \hyperlink{group__pustowka__encoder_ga9fe7ca911358cd267bacb01ceed426ed}{encoders\_\-reset}()~encoders\_\-write(0,0)
\begin{DoxyCompactList}\small\item\em Resets both encoders. \item\end{DoxyCompactList}\end{DoxyCompactItemize}
\subsection*{Functions}
\begin{DoxyCompactItemize}
\item 
unsigned int \hyperlink{group__pustowka__encoder_ga2bb92e75ace932c227b999813bf02aff}{encoders\_\-readLeft} (void)
\begin{DoxyCompactList}\small\item\em Read the left odometer. \item\end{DoxyCompactList}\item 
unsigned int \hyperlink{group__pustowka__encoder_ga0c464163534a8c0aa7ec050c8e9460e5}{encoders\_\-readRight} (void)
\begin{DoxyCompactList}\small\item\em Read the right odometer. \item\end{DoxyCompactList}\item 
void \hyperlink{group__pustowka__encoder_ga77c8c684f9d572edf7f85fde23ca390d}{encoders\_\-readAll} (unsigned int $\ast$enc\mbox{[}$\,$\mbox{]})
\begin{DoxyCompactList}\small\item\em Read both odometers. \item\end{DoxyCompactList}\item 
unsigned int \hyperlink{group__pustowka__encoder_gadaa18e9376adb2838d4db7b819070083}{encoders\_\-read} (unsigned char enc)
\begin{DoxyCompactList}\small\item\em Read both odometers. \item\end{DoxyCompactList}\item 
void \hyperlink{group__pustowka__encoder_ga9afcfd5f2888b73fa165cb174ddc6759}{encoders\_\-writeLeft} (unsigned int val)
\begin{DoxyCompactList}\small\item\em Write predefined value for left encoder. \item\end{DoxyCompactList}\item 
void \hyperlink{group__pustowka__encoder_gaaa61cfb8d7784d0a532402f8c762165c}{encoders\_\-writeRight} (unsigned int val)
\begin{DoxyCompactList}\small\item\em Write predefined value for right encoder. \item\end{DoxyCompactList}\item 
void \hyperlink{group__pustowka__encoder_ga19b9241b75d9aadb3293d06f45270120}{encoders\_\-write} (unsigned int left, unsigned int right)
\begin{DoxyCompactList}\small\item\em Write predefined values for the encoders. \item\end{DoxyCompactList}\item 
void \hyperlink{group__pustowka__encoder_gaf02e2149caeb6116f256783348031c86}{encoders\_\-init} (void)
\begin{DoxyCompactList}\small\item\em Inizialisation of encoders hardware. \item\end{DoxyCompactList}\item 
void \hyperlink{group__pustowka__encoder_gab663edeed94236bcf5c7b4cc508c0506}{encoders\_\-start} (void)
\begin{DoxyCompactList}\small\item\em Enables both encoders. \item\end{DoxyCompactList}\item 
void \hyperlink{group__pustowka__encoder_gaa9f0d84783bf4bc18350db551455ed81}{encoders\_\-stop} (void)
\begin{DoxyCompactList}\small\item\em Disables both encoders. \item\end{DoxyCompactList}\item 
void \hyperlink{group__pustowka__encoder_ga5664efae48b33c8cee94b5313a58b0a2}{encoders\_\-setDirection} (unsigned char left, unsigned char right)
\begin{DoxyCompactList}\small\item\em Defines wether the encoder should count backward or forward. \item\end{DoxyCompactList}\end{DoxyCompactItemize}


\subsection{Detailed Description}
Interrupt-\/driven encoder library for odometry readings. 
\begin{DoxyCode}
 #include <encoders.h> 
\end{DoxyCode}
 This module is used to read the encoders count of the two motors of NXBot. Two timers of the microcontroller ATmega1281 are used, and are configured as counters. NXBot does not have cuadrature encoders, that means, we cannot be sure of the direction of the wheels. That is why an alternate method was used. The desired direction is taken as the real direction of the wheel. That is a naive approximation, but hoping that the inertia of the robot is not too strong, and that the robot will not be exposed to undesired forces agains its movements, it is valid. No interrupts are used for constantly reading the encoders. It is up to the user to do this task. 

\subsection{Define Documentation}
\hypertarget{group__pustowka__encoder_gad221dba2d598f81f78bb66ec479c9a93}{
\index{pustowka\_\-encoder@{pustowka\_\-encoder}!ENC\_\-FORWARD@{ENC\_\-FORWARD}}
\index{ENC\_\-FORWARD@{ENC\_\-FORWARD}!pustowka_encoder@{pustowka\_\-encoder}}
\subsubsection[{ENC\_\-FORWARD}]{\setlength{\rightskip}{0pt plus 5cm}\#define ENC\_\-FORWARD~0}}
\label{group__pustowka__encoder_gad221dba2d598f81f78bb66ec479c9a93}


Constant used to define the behavior of the encoders. When configured as FORWARD, the odometer increments its count with the counts of the encoder. \hypertarget{group__pustowka__encoder_gad22ac75fffb7e44913bff8e3916972a8}{
\index{pustowka\_\-encoder@{pustowka\_\-encoder}!ENC\_\-LEFT@{ENC\_\-LEFT}}
\index{ENC\_\-LEFT@{ENC\_\-LEFT}!pustowka_encoder@{pustowka\_\-encoder}}
\subsubsection[{ENC\_\-LEFT}]{\setlength{\rightskip}{0pt plus 5cm}\#define ENC\_\-LEFT~0}}
\label{group__pustowka__encoder_gad22ac75fffb7e44913bff8e3916972a8}


Constant used in \hyperlink{group__pustowka__encoder_gadaa18e9376adb2838d4db7b819070083}{encoders\_\-read()} function. \hypertarget{group__pustowka__encoder_ga67c39a2a0310bf458988c9965f480562}{
\index{pustowka\_\-encoder@{pustowka\_\-encoder}!ENC\_\-REVERSE@{ENC\_\-REVERSE}}
\index{ENC\_\-REVERSE@{ENC\_\-REVERSE}!pustowka_encoder@{pustowka\_\-encoder}}
\subsubsection[{ENC\_\-REVERSE}]{\setlength{\rightskip}{0pt plus 5cm}\#define ENC\_\-REVERSE~1}}
\label{group__pustowka__encoder_ga67c39a2a0310bf458988c9965f480562}


Constant used to define the behavior of the encoders. When configured as REVERSE, the odometer decrements its count with the counts of the encoder. \hypertarget{group__pustowka__encoder_ga27432c06a7d08af0da6941f75127a0bd}{
\index{pustowka\_\-encoder@{pustowka\_\-encoder}!ENC\_\-RIGHT@{ENC\_\-RIGHT}}
\index{ENC\_\-RIGHT@{ENC\_\-RIGHT}!pustowka_encoder@{pustowka\_\-encoder}}
\subsubsection[{ENC\_\-RIGHT}]{\setlength{\rightskip}{0pt plus 5cm}\#define ENC\_\-RIGHT~1}}
\label{group__pustowka__encoder_ga27432c06a7d08af0da6941f75127a0bd}


Constant used in \hyperlink{group__pustowka__encoder_gadaa18e9376adb2838d4db7b819070083}{encoders\_\-read()} function. \hypertarget{group__pustowka__encoder_ga9fe7ca911358cd267bacb01ceed426ed}{
\index{pustowka\_\-encoder@{pustowka\_\-encoder}!encoders\_\-reset@{encoders\_\-reset}}
\index{encoders\_\-reset@{encoders\_\-reset}!pustowka_encoder@{pustowka\_\-encoder}}
\subsubsection[{encoders\_\-reset}]{\setlength{\rightskip}{0pt plus 5cm}\#define encoders\_\-reset()~encoders\_\-write(0,0)}}
\label{group__pustowka__encoder_ga9fe7ca911358cd267bacb01ceed426ed}


Resets both encoders. Left and right encoders counts will be reset to zero. \hypertarget{group__pustowka__encoder_gafc6b8648337ac6e21a67245c288b12a8}{
\index{pustowka\_\-encoder@{pustowka\_\-encoder}!encoders\_\-resetLeft@{encoders\_\-resetLeft}}
\index{encoders\_\-resetLeft@{encoders\_\-resetLeft}!pustowka_encoder@{pustowka\_\-encoder}}
\subsubsection[{encoders\_\-resetLeft}]{\setlength{\rightskip}{0pt plus 5cm}\#define encoders\_\-resetLeft()~encoders\_\-writeLeft(0)}}
\label{group__pustowka__encoder_gafc6b8648337ac6e21a67245c288b12a8}


Resets left encoder. Left encoders count will be reset to zero. \hypertarget{group__pustowka__encoder_ga050a620db67d2e9687e40295e0d29722}{
\index{pustowka\_\-encoder@{pustowka\_\-encoder}!encoders\_\-resetRight@{encoders\_\-resetRight}}
\index{encoders\_\-resetRight@{encoders\_\-resetRight}!pustowka_encoder@{pustowka\_\-encoder}}
\subsubsection[{encoders\_\-resetRight}]{\setlength{\rightskip}{0pt plus 5cm}\#define encoders\_\-resetRight()~encoders\_\-writeRight(0)}}
\label{group__pustowka__encoder_ga050a620db67d2e9687e40295e0d29722}


Resets right encoder. Right encoders count will be reset to zero. 

\subsection{Function Documentation}
\hypertarget{group__pustowka__encoder_gaf02e2149caeb6116f256783348031c86}{
\index{pustowka\_\-encoder@{pustowka\_\-encoder}!encoders\_\-init@{encoders\_\-init}}
\index{encoders\_\-init@{encoders\_\-init}!pustowka_encoder@{pustowka\_\-encoder}}
\subsubsection[{encoders\_\-init}]{\setlength{\rightskip}{0pt plus 5cm}void encoders\_\-init (void)}}
\label{group__pustowka__encoder_gaf02e2149caeb6116f256783348031c86}


Inizialisation of encoders hardware. Configures Timer1 and Timer3 from ATmega1281 microcontroller as counters. The counters will begin the count only when \hyperlink{group__pustowka__encoder_gab663edeed94236bcf5c7b4cc508c0506}{encoders\_\-start()} has been called. Otherwise they remain disabled. \hypertarget{group__pustowka__encoder_gadaa18e9376adb2838d4db7b819070083}{
\index{pustowka\_\-encoder@{pustowka\_\-encoder}!encoders\_\-read@{encoders\_\-read}}
\index{encoders\_\-read@{encoders\_\-read}!pustowka_encoder@{pustowka\_\-encoder}}
\subsubsection[{encoders\_\-read}]{\setlength{\rightskip}{0pt plus 5cm}unsigned int encoders\_\-read (unsigned char {\em enc})}}
\label{group__pustowka__encoder_gadaa18e9376adb2838d4db7b819070083}


Read both odometers. This function facilitates the readings for both encoders, by using functions encoders\_\-getStateRight() and encoders\_\-getStateLeft(). Counts are in ticks, tick to meter transformation is done in the motors module. It exist only to accomplish the standard of a {\itshape read()\/} function for each sensor.


\begin{DoxyParams}{Parameters}
\item[{\em enc}]Constant to select which odometer will be readed. Use only ENC\_\-LEFT or ENC\_\-RIGHT. If other value is used, 0 is returned. \end{DoxyParams}
\begin{DoxyReturn}{Returns}
odometer count 
\end{DoxyReturn}
\hypertarget{group__pustowka__encoder_ga77c8c684f9d572edf7f85fde23ca390d}{
\index{pustowka\_\-encoder@{pustowka\_\-encoder}!encoders\_\-readAll@{encoders\_\-readAll}}
\index{encoders\_\-readAll@{encoders\_\-readAll}!pustowka_encoder@{pustowka\_\-encoder}}
\subsubsection[{encoders\_\-readAll}]{\setlength{\rightskip}{0pt plus 5cm}void encoders\_\-readAll (unsigned int $\ast$ {\em enc}\mbox{[}$\,$\mbox{]})}}
\label{group__pustowka__encoder_ga77c8c684f9d572edf7f85fde23ca390d}


Read both odometers. This function facilitates the readings for both encoders, by using functions encoders\_\-getStateRight() and encoders\_\-getStateLeft(). Counts are in ticks, tick to meter transformation is done in the motors module.


\begin{DoxyParams}{Parameters}
\item[{\em enc}]pointer to integer array where the first position is the value of the left odometer, second position is the value of the right odometer. \end{DoxyParams}
\hypertarget{group__pustowka__encoder_ga2bb92e75ace932c227b999813bf02aff}{
\index{pustowka\_\-encoder@{pustowka\_\-encoder}!encoders\_\-readLeft@{encoders\_\-readLeft}}
\index{encoders\_\-readLeft@{encoders\_\-readLeft}!pustowka_encoder@{pustowka\_\-encoder}}
\subsubsection[{encoders\_\-readLeft}]{\setlength{\rightskip}{0pt plus 5cm}unsigned int encoders\_\-readLeft (void)}}
\label{group__pustowka__encoder_ga2bb92e75ace932c227b999813bf02aff}


Read the left odometer. Reads the encoders count from the left motor, and increments or decrements left odometer count. Counts are in ticks, tick to meter transformation is done in the motors module.

\begin{DoxyReturn}{Returns}
left odometer count 
\end{DoxyReturn}
\hypertarget{group__pustowka__encoder_ga0c464163534a8c0aa7ec050c8e9460e5}{
\index{pustowka\_\-encoder@{pustowka\_\-encoder}!encoders\_\-readRight@{encoders\_\-readRight}}
\index{encoders\_\-readRight@{encoders\_\-readRight}!pustowka_encoder@{pustowka\_\-encoder}}
\subsubsection[{encoders\_\-readRight}]{\setlength{\rightskip}{0pt plus 5cm}unsigned int encoders\_\-readRight (void)}}
\label{group__pustowka__encoder_ga0c464163534a8c0aa7ec050c8e9460e5}


Read the right odometer. Reads the encoders count from the right motor, and increments or decrements right odometer count. Counts are in ticks, tick to meter transformation is done in the motors module.

\begin{DoxyReturn}{Returns}
right odometer count 
\end{DoxyReturn}
\hypertarget{group__pustowka__encoder_ga5664efae48b33c8cee94b5313a58b0a2}{
\index{pustowka\_\-encoder@{pustowka\_\-encoder}!encoders\_\-setDirection@{encoders\_\-setDirection}}
\index{encoders\_\-setDirection@{encoders\_\-setDirection}!pustowka_encoder@{pustowka\_\-encoder}}
\subsubsection[{encoders\_\-setDirection}]{\setlength{\rightskip}{0pt plus 5cm}void encoders\_\-setDirection (unsigned char {\em left}, \/  unsigned char {\em right})}}
\label{group__pustowka__encoder_ga5664efae48b33c8cee94b5313a58b0a2}


Defines wether the encoder should count backward or forward. This function is fundamental for counting purposes, due to the lack of cuadrature encoders. It defines wheter the counts of the encoders should be forward or backward (i.e. incrementing counts or decrementing counts). The counting direction is determined by the desired direction of the wheel. If the wheel direction is configured as forward, then the count increments over time. When the wheel direction is configured as backward, then the count decrements over time.


\begin{DoxyParams}{Parameters}
\item[{\em left}]direction for the left encoder. \item[{\em right}]direction for the right encoder. \end{DoxyParams}
\hypertarget{group__pustowka__encoder_gab663edeed94236bcf5c7b4cc508c0506}{
\index{pustowka\_\-encoder@{pustowka\_\-encoder}!encoders\_\-start@{encoders\_\-start}}
\index{encoders\_\-start@{encoders\_\-start}!pustowka_encoder@{pustowka\_\-encoder}}
\subsubsection[{encoders\_\-start}]{\setlength{\rightskip}{0pt plus 5cm}void encoders\_\-start (void)}}
\label{group__pustowka__encoder_gab663edeed94236bcf5c7b4cc508c0506}


Enables both encoders. \hypertarget{group__pustowka__encoder_gaa9f0d84783bf4bc18350db551455ed81}{
\index{pustowka\_\-encoder@{pustowka\_\-encoder}!encoders\_\-stop@{encoders\_\-stop}}
\index{encoders\_\-stop@{encoders\_\-stop}!pustowka_encoder@{pustowka\_\-encoder}}
\subsubsection[{encoders\_\-stop}]{\setlength{\rightskip}{0pt plus 5cm}void encoders\_\-stop (void)}}
\label{group__pustowka__encoder_gaa9f0d84783bf4bc18350db551455ed81}


Disables both encoders. The counting values will not be reset. Use \hyperlink{group__pustowka__encoder_ga9fe7ca911358cd267bacb01ceed426ed}{encoders\_\-reset()} if you want to reset counts. \hypertarget{group__pustowka__encoder_ga19b9241b75d9aadb3293d06f45270120}{
\index{pustowka\_\-encoder@{pustowka\_\-encoder}!encoders\_\-write@{encoders\_\-write}}
\index{encoders\_\-write@{encoders\_\-write}!pustowka_encoder@{pustowka\_\-encoder}}
\subsubsection[{encoders\_\-write}]{\setlength{\rightskip}{0pt plus 5cm}void encoders\_\-write (unsigned int {\em left}, \/  unsigned int {\em right})}}
\label{group__pustowka__encoder_ga19b9241b75d9aadb3293d06f45270120}


Write predefined values for the encoders. Standard function write which is an easy way to write both \hyperlink{structencoders}{encoders}


\begin{DoxyParams}{Parameters}
\item[{\em left}]New tick values for the left encoder. \item[{\em right}]New tick values for the right encoder. \end{DoxyParams}
\hypertarget{group__pustowka__encoder_ga9afcfd5f2888b73fa165cb174ddc6759}{
\index{pustowka\_\-encoder@{pustowka\_\-encoder}!encoders\_\-writeLeft@{encoders\_\-writeLeft}}
\index{encoders\_\-writeLeft@{encoders\_\-writeLeft}!pustowka_encoder@{pustowka\_\-encoder}}
\subsubsection[{encoders\_\-writeLeft}]{\setlength{\rightskip}{0pt plus 5cm}void encoders\_\-writeLeft (unsigned int {\em val})}}
\label{group__pustowka__encoder_ga9afcfd5f2888b73fa165cb174ddc6759}


Write predefined value for left encoder. Write a certain value to the left encoder. Normally used to reset the encoders count, or for the definition of a new robot position. This function is mainly used for resetting the counts and also for implementing an up/down counter (incremental/decremental), behavior which is implemented by the function \hyperlink{group__pustowka__encoder_ga5664efae48b33c8cee94b5313a58b0a2}{encoders\_\-setDirection()}.


\begin{DoxyParams}{Parameters}
\item[{\em val}]New tick values for the encoder. \end{DoxyParams}
\hypertarget{group__pustowka__encoder_gaaa61cfb8d7784d0a532402f8c762165c}{
\index{pustowka\_\-encoder@{pustowka\_\-encoder}!encoders\_\-writeRight@{encoders\_\-writeRight}}
\index{encoders\_\-writeRight@{encoders\_\-writeRight}!pustowka_encoder@{pustowka\_\-encoder}}
\subsubsection[{encoders\_\-writeRight}]{\setlength{\rightskip}{0pt plus 5cm}void encoders\_\-writeRight (unsigned int {\em val})}}
\label{group__pustowka__encoder_gaaa61cfb8d7784d0a532402f8c762165c}


Write predefined value for right encoder. Write a certain value to the right encoder. Normally used to reset the encoders count, or for the definition of a new robot position. This function is mainly used for resetting the counts and also for implementing an up/down counter (incremental/decremental), behavior which is implemented by the function \hyperlink{group__pustowka__encoder_ga5664efae48b33c8cee94b5313a58b0a2}{encoders\_\-setDirection()}.


\begin{DoxyParams}{Parameters}
\item[{\em val}]New tick values for the encoder. \end{DoxyParams}
